package com.blank.shop.dubbo.runner;

import com.blank.shop.dubbo.api.User;
import com.blank.shop.dubbo.api.UserService;
import com.blank.shop.dubbo.service.RestCallService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <br/>Date 2021/9/1
 * <br/>Time 18:21:21
 *
 * @author _blank
 */
@Configuration
public class ApplicationRunnerBean extends RestCallService {

    @DubboReference
    private UserService userService;

    public ApplicationRunner userServiceRunner = args -> {
        User user = new User();
        user.setId(1L);
        user.setName("小马哥");
        user.setAge(33);

        // save User
        System.out.printf("UserService.save(%s) : %s\n", user, userService.save(user));

        // find all Users
        System.out.printf("UserService.findAll() : %s\n", userService.findAll());

        // remove User
        System.out.printf("UserService.remove(%d) : %s\n", user.getId(), userService.remove(user.getId()));
    };

    public ApplicationRunner callRunner = args -> {
        System.out.println("=============================================");
        this.callAll();
        System.out.println("=============================================");
    };

    @Bean
    public ApplicationRunner getUserServiceRunner() {
        return this.userServiceRunner;
    }

    @Bean
    public ApplicationRunner getCallRunner() {
        return this.callRunner;
    }

}
